#ifndef WIME_ROUTER_H_21041234567890_
#define WIME_ROUTER_H_21041234567890_

//#include "wime_configall.h"
//#include "wime_network.h"
typedef char TWimeRouter;
typedef char TWimeNetwork;

/******************************************************************************
 * Single path infomation, return for user interface
 @ direction: direction of current path
 @ NextNodeName: key words of next node in current direction
 @ NextNodeDistance;	distance to next node in current direction, minus
 	 indicates unknown.
 *****************************************************************************/ 
typedef struct
{
	char NextNodeName[20];	
	unsigned char NextNodeIEEEAddress[8];//64-bits IEEE Extended Address
	int  Direction;	
	int  NextNodeDistance;	 
}TWimeSinglePath;

/******************************************************************************
 * Internal Single path infomation, include dedicated information for BF
 @ m, n, k, NodeSum: for Bloom Filter Algorithm.
 @ vlist: Bloom Filter vector list head address, malloc when initialization
 @ interinfo: interested informatin for other module
 *****************************************************************************/ 
typedef struct
{
	int m;
	int n;
	unsigned char * vlist;		
	TWimeSinglePath interinfo;
}TWimeInternalSinglePath;

/******************************************************************************
 * General infomation on paths involved in a node
 @ NodeName: name of current node
 @ PathSum: number of available paths
 @ Configured: indicate vlist has been malloced for space. set true when create 
   during initialization. this can be used for flag of free function.
 @ PathInfo: detailed Information of each path
 *****************************************************************************/ 
typedef struct
{	char NodeName[20];
	unsigned char NodeIEEEAddress[8];//64-bits IEEE Extended Address
	unsigned char PathSum;		
	bool Configured;	
	TWimeInternalSinglePath PathInfo[10];		 
}TWimeRouterNode;

/*
typedef struct{
  TWimeNetwork * net;
  TWimeSinglePath singlepath;
  TWimeNode generalpath;
}TWimeRouter;*/

/******************************************************************************
 * theNode: indicate a node information.
 * if used in a real node, the variable is - theNode;
 * else if used in a single pc for simulation, theNode may be replaced by 
 * theNode[NodeSum], where NodeSum is the quantity of nodes.
 *****************************************************************************/

/******************************************************************************
 * Load a node configuration file, and allocate space for vlist
   the function can be recalled more than once.
 *****************************************************************************/
TWimeRouter * wrouter_create( TWimeNetwork * net );

/******************************************************************************
 * Free the memory vlist point to, which is dynamically allocated in 
   wrouter_create
 *****************************************************************************/
void wrouter_free( TWimeRouter * router );

/******************************************************************************
 * Request a specific router. This function is used by higher layer which try to 
 * acquire a direction information from one point to another point.
 * 
 * @src
 * source node name key words, up to 8 characters. It is used to verify whether 
 * the current node is the expected source node. If set as null, the function 
 * will set current node as default node.
 *
 * @dest 
 * destination node name key words, up to 8 characters. 
 *
 * @path
 * source node name key words, up to 8 characters. It is used to verify whether 
 * the current node is the expected source node. If set as null, the function 
 * will set current node as default node.
 *
 * @return
 * Status of the request answer.
 * 0: failure, no information about the given dest.
 * 1: success, and the answer is presented.
 * 2: failure, the answer is not presented immediately.
 * 3: failure, src name is not complied with the current node.
 *****************************************************************************/ 
int wrouter_read( TWimeNetwork * net, char * src, char * dest, TWimeSinglePath * path );
 
int wrouter_write( TWimeRouter * router, char * src, char * dest );

/* control the state evolution of WiME router in the future */
void wrouter_evolve( TWimeRouter * router );


/******************************************************************************
 * Check if dest belong to the given path set.
 * 
 * @dest
 * destination node name.
 *
 * @PathNumber
 * the number of path in all available paths
 *
 * @return
 * false: dest does not belong to given path.
 * true: dest belongs to given path .
 *****************************************************************************/ 
bool AssertNode ( char * dest, int PathNumber );

/******************************************************************************
 * Hash functions
 *****************************************************************************/ 
long HashFun1(char * url, long size);
long HashFun2(char * url, long size);
long HashFun3(char * url, long size);
long HashFun4(char * url, long size);

typedef char TWimeNetwork

#endif